package com.scsj.supermarket.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.scsj.supermarket.R;
import com.scsj.supermarket.bean.FiltrateChildBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 右侧滑动栏价格筛选
 */

public class FiltrateChildAdapter extends RecyclerView.Adapter<FiltrateChildAdapter.MyViewHolder> {

    private LayoutInflater minflater;
    private Context mContext;
    protected List<FiltrateChildBean> mDatas = new ArrayList<>();


    public FiltrateChildAdapter(Context context) {
        this.mContext = context;
        minflater = LayoutInflater.from(context);
    }

    public void addAllData(List<FiltrateChildBean> mDatas) {
        this.mDatas.addAll(mDatas);
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = minflater.inflate(R.layout.item_filtrate_child_layout, viewGroup, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, final int i) {
        FiltrateChildBean itemBean = mDatas.get(i);
        myViewHolder.child_name_tv.setText(itemBean.getName());
    }

    @Override
    public int getItemCount() {
        if (mDatas != null) {
            return mDatas.size();
        } else {
            return 0;
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView child_name_tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            child_name_tv = itemView.findViewById(R.id.child_name_tv);

        }
    }
}
